package org.ihelpuoo.orm.handler;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;

import org.ihelpuoo.lang.ObjectUtils;
import org.ihelpuoo.orm.III;
import org.ihelpuoo.orm.ObjectRule;
import org.ihelpuoo.orm.filter.FieldFilter;
import org.ihelpuoo.orm.filter.Filter;

public abstract class ReadMapFieldHandler extends ReadCollectionFieldHandler
{

	public ReadMapFieldHandler(ObjectProcessor beanHandler)
	{
		super(beanHandler);
	}

	@Override
	protected void processWithoutExceptionHandle(ObjectRule r, Field f, Object src, Object obj,
			FieldFilter actived, FieldFilter locked, String prefix) throws Exception
	{
		Class subType = r.getComponentType(f);
		Filter filter = evalBeanFilter(r,f,obj);
		List list = evalSubList(r,f,src,filter,obj,subType);
		Map<String, Object> map = III.buildMapByList(processor.manual,list);
		if (null == map || map.size() == 0)
			return;
		Method setter = ObjectUtils.getSetter(obj.getClass(),f);
		setter.invoke(obj,new Object[]{map});
	}

}
